//
//  ViewController.m
//  CulinaryKnowledge
//
//  Created by CaoHung on 7/16/14.
//  Copyright (c) 2014 GreenSun. All rights reserved.
//

#import "HomeViewController.h"
#import "QuestionsViewController.h"
#import "EndangeredSpeciesViewController.h"
#import "InfoViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    mIndex = 0;
    mPoints = 0;
    
    self.title = @"タイトル";
    // Set backgroundColor
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_home.png"]];
    
    //Hide navigationController
    self.navigationController.navigationBarHidden = YES;
    
    /* Save result
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(saveResult:)
                                                 name:@"saveResult"
                                               object:nil];
     */
}

- (void)viewDidAppear:(BOOL)animated
{
    self.title = @"タイトル";
    //Show navigationController
    self.navigationController.navigationBarHidden = YES;
}

/* Save result
- (void)saveResult:(NSNotification *)result
{
    mIndex = [[[result object]objectForKey:@"index"] integerValue];
    mPoints = [[[result object]objectForKey:@"points"] integerValue];
}
 */

- (IBAction)goToQuestionsViewController:(id)sender {
    //Get QuesionsList and answers
    NSDictionary *quesionsList = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"QuestionsList" ofType:@"plist"]];
    
    QuestionsViewController *viewContronller = [[QuestionsViewController alloc]init];
    
    [viewContronller setMQuesionsList:quesionsList];
    
    /* Save result
    [viewContronller setSaveIndex:mIndex];
    [viewContronller setSavePoints:mPoints];
     */
    
    [self.navigationController pushViewController:viewContronller animated:YES];
}

- (IBAction)goToEndangeredSpeciesViewController:(id)sender {
    self.title = @"戻る";
    EndangeredSpeciesViewController *viewContronller = [[EndangeredSpeciesViewController alloc]init];
    [self.navigationController pushViewController:viewContronller animated:YES];
}

// Go to App Info
- (IBAction)goToAppInfoController:(id)sender {
    self.title = @"戻る";
    InfoViewController *viewContronller = [[InfoViewController alloc]init];
    [self.navigationController pushViewController:viewContronller animated:YES];
}

// Go to Web shogakukan shop
- (IBAction)goToWebsite:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.shogakukan.co.jp/books/detail/_isbn_9784093883511"]];
}

-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
